<?php

// 
// Returns the YouTube or Blip.TV ID from the header redirect of a VodPod embed
//
// Sample call:  http://joemaller.com/services/vodpod_id_extractor.php?vodpod=481944&callback=? 
// 

echo "/*" . 'http://widgets.vodpod.com/w/video_embed/ExternalVideo.' . intval( $_GET['vodpod'] ) . "*/\n\n";

$headers = get_headers('http://widgets.vodpod.com/w/video_embed/ExternalVideo.' . intval( $_GET['vodpod'] ), 1);

if (preg_match('%www.youtube.com/v/([^&]+)%', $headers['Location'][0], $url))
	echo htmlspecialchars($_GET['callback']) . '({ "_type":"youtube", "_id":"' . $url[1] . '" })';


if (!is_array($headers['Location']) && preg_match('%blip.tv/rss/flash/([0-9]+)&%', $headers['Location'], $url))
	echo htmlspecialchars($_GET['callback']) . '({ "_type":"bliptv", "_id":"' . $url[1] . '" })';




echo "/*\n\n";

print_r($headers);

echo '*/';
?>